var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require('path');
var scssExtract = new ExtractTextPlugin({
    filename: "stylesheets/scss.css",
    disable: false,
    allChunks: true
});
var lessExtract = new ExtractTextPlugin({
    filename: "stylesheets/less.css",
    disable: false,
    allChunks: true
});
var cssExtract = new ExtractTextPlugin({
    filename: "stylesheets/css.css",
    disable: false,
    allChunks: true
});
//获取webpack对象
module.exports = {
//webpack加压缩后为了方便调试生成sourceMap文件配置
    devtool: 'cheap-module-eval-source-map',
    //页面入口文件配置
    entry: [
        //热加载
        'webpack-hot-middleware/client',
        //进口文件舍去后面的js
        './index'
    ],
    output: {
        // __dirname此变量是node.js中的变量获取当前路径 合并
        path: path.join(__dirname, 'static'),
        //打包后的文件名
        filename: "[name].js?[hash]-[chunkhash]",
        //网站运行时的访问路径，不设置的话，打包出的html中的默认引用的路径会是相对路径
        publicPath: '/static/'
    },
    module: {
        loaders: [
            {
                test: /\.css$/,
                loader: cssExtract.extract({fallbackLoader: 'style-loader', loader: 'css-loader!sass-loader'})
            },
            {
                test: /\.scss$/,
                loader: scssExtract.extract({fallbackLoader: 'style-loader', loader: 'css-loader!sass-loader'})
            },
            {
                test: /\.less$/,
                loader: lessExtract.extract({fallbackLoader: 'style-loader', loader: 'css-loader!less-loader'})
            },
            {test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/, include: __dirname},
            {test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'},

        ]
    },
    /*devtool: "source-map",*/
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery"
        }),
        scssExtract,
        cssExtract,
        lessExtract,
        new webpack.optimize.CommonsChunkPlugin({name: "common", filename: "common.js"})
    ],
    resolve: {
        extensions: ['.js', '.jsx', '.json', '.scss']
    },
};